class ProductsController < ApplicationController
  def index
    @products = Product.all
  end

  def show
    @product = Product.find(params[:id])
    console
  end


  def add_to_cart
    @product = Product.find(params[:id])

    if !current_cart.products.include?(@product)
      current_cart.add_product_to_cart(@product)
      flash[:notice] = "add #{@product.title} to cart success"
    else
      flash[:warning] = "you had added the item"
    end
    redirect_back(fallback_location: products_path)
  end

end
